rebase 후에는 항상 git push --force-with-lease. git pull은 사용하지 말 것.

Answer from Chat GPT 5

# Git Rebase 후 Push 에러와 해결방법

## 문제 상황

`git rebase`를 수행한 뒤 `git push`를 하면 다음과 같은 에러가 발생한다:

```bash
➜ git push
To https://github.com/curinginnos/racketime-api.git
 ! [rejected]          feat/group-lesson-CU-86etfu1kb -> feat/group-lesson-CU-86etfu1kb (non-fast-forward)
error: failed to push some refs to 'https://github.com/curinginnos/racketime-api.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

git pull을 실행하면 merge 커밋이 생기면서 커밋 히스토리가 꼬여버리는 문제가 발생한다.


원인


해결 방법

1. 표준 절차

# 0) 최신 원격 가져오기
git fetch origin

# 1) 내가 앞선 커밋만 있는지 확인
git rev-list --left-right --count origin/feat...feat
# 출력 예: "0 5" → 로컬이 5개 앞서고 원격은 0개 앞섬

# 2) 안전 강제 푸시
git push --force-with-lease origin feat/group-lesson-CU-86etfu1kb

2. 원격에 새 커밋이 존재할 경우

git fetch origin
git rebase origin/feat/group-lesson-CU-86etfu1kb
# 충돌 해결 후
git push --force-with-lease origin feat/group-lesson-CU-86etfu1kb

3. 이미

git pull

로 꼬였을 때 되돌리기

git reflog           # rebase 직후 커밋 해시 확인
git reset --hard <rebase_끝난_커밋>
git push --force-with-lease origin feat/group-lesson-CU-86etfu1kb

재발 방지 방법

git config --global pull.rebase true
git config --global rebase.autoStash true
git config --global alias.fp "push --force-with-lease"

브랜치 보호 규칙이 걸려 있을 때

git checkout -b feat/rebased
git push origin feat/rebased

빠른 진단 명령어 모음

git status -sb
git log --oneline --graph --decorate --all --max-count=25
git rev-list --left-right --count origin/feat...feat

핵심 요약